﻿using AutoMapper;
using Enferno.Public.Web.Models;
using Enferno.StormApiClient.Products;
using Enferno.StormApiClient.Shopping;

namespace Enferno.Public.Web.Mappers.Resolvers
{
    public class ProductPriceResolver<TPriceModel> : ValueResolver<Product, TPriceModel>
        where TPriceModel: PriceModel, new()
    {
        protected override TPriceModel ResolveCore(Product product)
        {
            return new TPriceModel
            {
                Display = PriceCalulator.Price(product.Price, product.VatRate),
                Catalog = PriceCalulator.Price(product.PriceCatalog ?? product.Price, product.VatRate),
                Recommended = PriceCalulator.Price(product.PriceRecommended ?? product.Price, product.VatRate),
                Original = PriceCalulator.Price(product.Price, product.VatRate),
                VatRate = product.VatRate,
                PricelistId = product.PriceListId,
                IsFromPrice = false
            };
        }
    }

    public class ProductItemPriceResolver<TPriceModel> : ValueResolver<ProductItem, TPriceModel>
        where TPriceModel: PriceModel, new()
    {
        protected override TPriceModel ResolveCore(ProductItem productItem)
        {
            return new TPriceModel
            {
                Display = PriceCalulator.Price(productItem.Price, productItem.VatRate),
                Catalog = PriceCalulator.Price(productItem.PriceCatalog ?? productItem.Price, productItem.VatRate),
                Recommended = PriceCalulator.Price(productItem.PriceRecommended ?? productItem.Price, productItem.VatRate),
                Original = PriceCalulator.Price(productItem.Price, productItem.VatRate),
                VatRate = productItem.VatRate,
                PricelistId = productItem.PriceListId.GetValueOrDefault(0),
                IsFromPrice = false
            };
        }
    }

    public class BasketPriceResolver<TPriceModel> : ValueResolver<BasketItem, TPriceModel>
        where TPriceModel: PriceModel, new()
    {
        protected override TPriceModel ResolveCore(BasketItem basketItem)
        {
            return new TPriceModel
            {
                Display = PriceCalulator.Price(basketItem.PriceDisplay, basketItem.VatRate),
                Catalog = PriceCalulator.Price(basketItem.PriceCatalog ?? basketItem.PriceDisplay, basketItem.VatRate),
                Recommended = PriceCalulator.Price(basketItem.PriceRecommended ?? basketItem.PriceDisplay, basketItem.VatRate),
                Original = PriceCalulator.Price(basketItem.PriceOriginal, basketItem.VatRate),
                VatRate = basketItem.VatRate,
                PricelistId = basketItem.PriceListId,
                IsFromPrice = false
            };
        }
    }


}
